package ui;

import org.newdawn.slick.Graphics;

import util.Rect;
import util.Settings;

/**
 * Custom slider class.
 * @author VincentLy
 */
public class CustomSlider extends Rect{

	private CustomSliderTab cst;
	private String text;
	private float d;
	private char name;
	
	public CustomSlider(float x,float y,String s,char c,float d) {
		super(x,y,Settings.sliderX,Settings.sliderY,5);
		cst = new CustomSliderTab(x+d*Settings.sliderX-Settings.sliderTabX/2,y+Settings.sliderY/2-Settings.sliderTabY/2);
		text = s;
		name = c;
	}	

	/**
	 * @return slider text
	 * @author VincentLy
	 */
	public String text(){return text + (int)(d*100)+"%";}
	
	/**
	 * @return character reference
	 * @author VincentLy
	 */
	public char name(){return name;}
	
	/**
	 * @return the slider tab
	 * @author VincentLy
	 */
	public CustomSliderTab tab(){return cst;}
	
	/**
	 * @return slider value
	 * @author VincentLy
	 */
	public float val(){return d;}
	
	/**
	 * Updates the slider value when sliding.
	 * @author VincentLy
	 */
	public void update(){d = (cst.x()-100)/Settings.sliderX;}
	
	/**
	 * Draws the custom slider.
	 * @author VincentLy
	 */
	public void draw(Graphics g){
		g.setColor(color());
		g.draw(this);
		cst.draw(g);
	}
}